package demo.platform;

import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.ImageIcon;

public abstract class Entity {

	private int x;
	private int y;
	private int width, height;
	private int dx,dy;
	private int dir;
	
	private boolean isFalling;
	private boolean isJumping;
	private boolean isDead;
	private Rectangle[] CollidingRectangles;
	private Image entityImage;
	private Image[] entityAnimation;
	private String path_to_sprite;
	
	public Entity() {
		initEntity();
	}
	
	public void initEntity() {
		
	}
	
	public int getEntityX() {
		return this.x;
	}
	
	public int getEntityY() {
		return y;
	}
	
	public int getDX() {
		return dx;
	}
	
	public int getDY() {
		return dy;
	}
	
	public int getLeftX() {
		return x;
	}
	
	public int getRightX() {
		return x + width;
	}
	
	public int getTopY() {
		return y;
	}
	
	public int getBottomY() {
		return y + height;
	}

	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public int getDirection() {
		return dir;
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public void setY(int y) {
		this.y = y;
	}
	
	public void setDX(int d) {
		dx = d;
	}
	
	public void setDY(int y) {
		dy = y;
	}
	
	public void setSpritePath(String path) {
		path_to_sprite = path;
	}
	
	public void setFalling(boolean fall) {
		isFalling = fall;
	}
	
	public void setDirection(int d) {
		dir = d;
	}
	
	public void setJumping(boolean j) {
		isJumping = j;
	}
	
	public void setEntityDeath(boolean d) {
		isDead = d;
	}
	
	public Rectangle[] getCollidingRectangles() {
		return CollidingRectangles;
	}
	
	public boolean isEntityDead() {
		return isDead;
	}
	
	public Image getEntitySprite() {
		return entityImage;
	}
	
	public Rectangle getEntityBounds() {
		return new Rectangle(x, y, width, height);
	}
	
	public boolean isJumping() {
		return isJumping;
	}
	
	public boolean isFalling() {
		return isFalling;
	}
	
	public void move() {
		x += dx;
		y += dy;
		//dx = 0;
		//dy = 0;
	}
	
	/**
	 * Loads image and sets entity width and height.
	 */
	public void loadSpriteImage() {
		ImageIcon ii = new ImageIcon(path_to_sprite);
		entityImage = ii.getImage();
		width = entityImage.getWidth(null);
		height = entityImage.getHeight(null);
	}
	
	/**
	 * Initializes rectangle array.
	 */
	public void initCollisions() {
		CollidingRectangles = new Rectangle[4];
		CollidingRectangles[0] = new Rectangle();
		CollidingRectangles[1] = new Rectangle();
		CollidingRectangles[2] = new Rectangle();
		CollidingRectangles[3] = new Rectangle();
	}
}
